package com.yicong.ants.scenic.adapter

import android.view.LayoutInflater
import com.chad.library.adapter.base.BaseQuickAdapter
import com.x.livesdk.BaseDataBindingHolder
import com.yicong.ants.R
import com.yicong.ants.databinding.ScenicListItemBinding
import com.yicong.ants.databinding.ScenicTagItemBinding
import com.yicong.ants.databinding.ScenicTagItemDarkBinding
import com.yicong.ants.scenic.data.ScenicItem

class ScenicListAdapter :
    BaseQuickAdapter<ScenicItem, BaseDataBindingHolder<ScenicListItemBinding>>(R.layout.scenic_list_item) {
    init {
        setEnableLoadMore(false)
    }

    var refreshListener: (() -> Unit)? = null

    override fun setNewData(data: MutableList<ScenicItem>?) {
        super.setNewData(data)
        setEmptyView(R.layout.view_scenic_empty)
    }

    override fun convert(
        holder: BaseDataBindingHolder<ScenicListItemBinding>,
        item: ScenicItem
    ) {
        holder.dataBinding?.data = item
        holder.dataBinding?.tagLl?.removeAllViews()
        item.themeGroups?.split(",")?.forEachIndexed { index, item ->
            if (index == 0) {
                ScenicTagItemDarkBinding.inflate(
                    LayoutInflater.from(holder.itemView.context),
                    holder.dataBinding?.tagLl,
                    true
                ).titleTv.text = item
            } else {
                ScenicTagItemBinding.inflate(
                    LayoutInflater.from(holder.itemView.context),
                    holder.dataBinding?.tagLl,
                    true
                ).titleTv.text = item
            }
        }
    }
}